public class SolvingEquations
{
    public void Run()
    {
        firstplus();
    }
    public static void Function(int a, int b, int c)
    {
        if (a == 0)
        {
            if (b == 0)
            {
                if (c == 0)
                {
                    Console.WriteLine("原式为恒等式");
                }
                else
                    Console.WriteLine("x无解");
            }
            else
            {
                Console.WriteLine(-c / b);
            }
        }
        else
        {
            double x1 = (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
            double x2 = (-b - Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
            int m = b * b - 4 * a * c;
            if (m > 0)
            {
                Console.WriteLine(x1);
                Console.WriteLine(x2);
            }
            else if (m == 0)
            {
                Console.WriteLine(x1);
            }
            else
            {
                Console.WriteLine("x无解");
            }
        }
    }
    public static void read()
    {
        var input = Console.ReadLine();

        var x = input.Substring(0, 1);
        var y = input.Substring(2, 1);
        var z = input.Substring(4, 1);

        var a = int.Parse(x);
        var b = int.Parse(y);
        var c = int.Parse(z);

        Function(a, b, c);
    }
    public static void first()
    {
        read();
        Console.WriteLine("是否继续？(yes/no）");
        var input2 = Console.ReadLine();
        var n = input2.Substring(0, 1);
        while (n == "Y" || n == "y")
        {
            read();
            Console.WriteLine("是否继续？(yes/no）");
            var input3 = Console.ReadLine();
            n = input3.Substring(0, 1);
        }
    }
    public static void readplus()
    {
        var input = Console.ReadLine();
        if (input[input.Length - 1] != ' ')
        {
            input = input + " ";
        }
        int x = 0;
        int[] a = new int[3];
        int y = 0;
        for (int i = 0; i < input.Length; i++)
        {
            if (input[i] == ' ')
            {
                a[y] = int.Parse(input.Substring(x, i - x));
                x = i;
                y += 1;
            }
        }
        //if (input[input.Length - 1] != ' ')
        //{
        //    a[2] = int.Parse(input.Substring(x, input.Length - x));
        //}
        Function(a[0], a[1], a[2]);
    }
    public static void split()
    {
        var input = Console.ReadLine();
        string phrase = input;
        string[] words = phrase.Split(' ');
        int[] number = new int[3];

        for (int x = 0; x < 3; x++)
        {
            number[x] = int.Parse(words[x]);
            //Console.WriteLine(number[x]);
        }

        //var a = int.Parse(words[0]);
        //var b = int.Parse(words[1]);
        //var c = int.Parse(words[2]);
        //Console.WriteLine(a);
        //Console.WriteLine(b);
        //Console.WriteLine(c);
        Function(number[0], number[1], number[2]);
    }
    public static void firstplus()
    {
        split();
        Console.WriteLine("是否继续？(yes/no）");
        var input2 = Console.ReadLine();
        var n = input2.Substring(0, 1);
        while (n == "Y" || n == "y")
        {
            split();
            Console.WriteLine("是否继续？(yes/no）");
            var input3 = Console.ReadLine();
            n = input3.Substring(0, 1);
        }
    }
    public static void ImaginaryNumber(double a, double b, double c)
    {
        double d = -b / (2 * a);
        double e = Math.Sqrt(4 * a * c - b * b) / (2 * a);
        if (e == 1)
        {
            Console.WriteLine($"{d}+i");
            Console.WriteLine($"{d}-i");
        }
        else
        {
            Console.WriteLine($"{d}+{e}i");
            Console.WriteLine($"{d}-{e}i");
        }
    }
    public static void Function2(double a, double b, double c)
    {

        {
            if (a == 0)
            {
                if (b == 0)
                {
                    if (c == 0)
                    {
                        Console.WriteLine("原式为恒等式");
                    }
                    else
                        Console.WriteLine("x无解");
                }
                else
                {
                    Console.WriteLine("退化为一元一次方程");
                    Console.WriteLine(-c / b);
                }
            }
            else
            {
                double x1 = (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
                double x2 = (-b - Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
                double m = b * b - 4 * a * c;
                if (m > 0)
                {
                    Console.WriteLine("有两个不同的实数根");
                    Console.WriteLine(x1);
                    Console.WriteLine(x2);
                }
                else if (m == 0)
                {
                    Console.WriteLine("有一个实数根");
                    Console.WriteLine(x1);
                }
                else
                {
                    Console.WriteLine("有两个不同的虚数根");
                    ImaginaryNumber(a, b, c);
                }
            }
        }
    }
    public static void split2()
    {
        var input = Console.ReadLine();
        string phrase = input;
        string[] words = phrase.Split(' ');
        double[] number = new double[3];

        for (int x = 0; x < 3; x++)
        {
            number[x] = double.Parse(words[x]);
            //Console.WriteLine(number[x]);
        }

        //var a = int.Parse(words[0]);
        //var b = int.Parse(words[1]);
        //var c = int.Parse(words[2]);
        //Console.WriteLine(a);
        //Console.WriteLine(b);
        //Console.WriteLine(c);
        Function2(number[0], number[1], number[2]);
    }
    public static void plus()
    {
        split2();
        Console.WriteLine("是否继续？(yes/no）");
        var input2 = Console.ReadLine();
        var n = input2.Substring(0, 1);
        while (n == "Y" || n == "y")
        {
            split2();
            Console.WriteLine("是否继续？(yes/no）");
            var input3 = Console.ReadLine();
            n = input3.Substring(0, 1);
        }
    }
    public static void CubicPower()
    {
        //x*x*x+x=20
        Console.WriteLine("解方程x^3+x-20=0");
        double a = 0;
        while (a * a * a + a < 20)
        {
            if ((a + 1) * (a + 1) * (a + 1) + (a + 1) >= 20)
            {
                break;
            }
            a++;
        }
        while (a * a * a + a < 20)
        {
            if ((a + 0.1) * (a + 0.1) * (a + 0.1) + (a + 0.1) >= 20)
            {
                break;
            }
            a = a + 0.1;
        }
        while (a * a * a + a < 20)
        {
            if ((a + 0.01) * (a + 0.01) * (a + 0.01) + (a + 0.01) >= 20)
            {
                break;
            }
            a = a + 0.01;
        }
        while (a * a * a + a < 20)
        {
            if ((a + 0.001) * (a + 0.001) * (a + 0.001) + (a + 0.001) >= 20)
            {
                break;
            }
            a = a + 0.001;
        }
        while (a * a * a + a < 20)
        {
            if ((a + 0.0001) * (a + 0.0001) * (a + 0.0001) + (a + 0.0001) >= 20)
            {
                break;
            }
            a = a + 0.0001;
        }
        var message = $"{a:f3}";
        Console.WriteLine(message);
    }
}
